<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    var obj = {
      a:10,
      b:20,
      msg:10
    }
    var a = obj.a;

   Object.defineProperty(obj,'a',{
     get(){ // get 劫持了这个对象属性的获取
      console.log("a属性获取了");
      return a;
     },
     set(val){  //劫持了这个对象这个属性的设置
      console.log("a属性设置了");
      a = val;
      return a;
     }
   })
    // console.log(obj.a);
    obj.a=30;
    console.log(obj);
  </script>
</body>
</html>